/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.factory.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.factory.entity.FactorySample;
import com.pitop.factory.service.FactorySampleSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工厂的样品 控制器
 *
 * @author pi-top
 */
@RestController
@RequestMapping("/factorySample")
@Slf4j
@Api(value = "工厂的样品控制器", description = "工厂的样品控制器")
public class FactorySampleCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private FactorySampleSV factorySampleSV;


    /**
     * 查询FactorySample一个详情信息
     *
     * @param id          id
     * @param sampleCode  样品编码
     * @param factoryCode 工厂编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询FactorySample一个详情信息", notes = "查询FactorySample一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public FactorySample load(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        if (id == null) {
            return null;
        }
        if (sampleCode == null) {
            return null;
        }
        if (factoryCode == null) {
            return null;
        }
        FactorySample factorySample = factorySampleSV.load(id, sampleCode, factoryCode);
        log.info(JSON.toJSONString(factorySample));
        return factorySample;
    }


    /**
     * 根据条件id查询FactorySample一个详情信息
     *
     * @param id id
     * @return BeanRet
     */
    @ApiOperation(value = "查询FactorySample一个详情信息", notes = "查询FactorySample一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public FactorySample loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        FactorySample factorySample = factorySampleSV.loadById(id);
        log.info(JSON.toJSONString(factorySample));
        return factorySample;
    }

    /**
     * 根据条件sampleCode查询FactorySample一个详情信息
     *
     * @param sampleCode 样品编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询FactorySample一个详情信息", notes = "查询FactorySample一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/list/sampleCode/{sampleCode}")
    @ResponseBody
    public List<FactorySample> listBySampleCode(@PathVariable java.lang.String sampleCode) {
        if (sampleCode == null) {
            return null;
        }
        List<FactorySample> factorySamples = factorySampleSV.listBySampleCode(sampleCode);
        log.info(JSON.toJSONString(factorySamples));
        return factorySamples;
    }

    /**
     * 根据条件factoryCode查询FactorySample一个详情信息
     *
     * @param factoryCode 工厂编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询FactorySample一个详情信息", notes = "查询FactorySample一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/list/factoryCode/{factoryCode}")
    @ResponseBody
    public List<FactorySample> listByFactoryCode(@PathVariable java.lang.String factoryCode) {
        if (factoryCode == null) {
            return null;
        }
        List<FactorySample> factorySamples = factorySampleSV.listByFactoryCode(factoryCode);
        log.info(JSON.toJSONString(factorySamples));
        return factorySamples;
    }


    /**
     * 查询FactorySample信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询FactorySample信息集合", notes = "查询FactorySample信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable,禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "ver", value = "版本", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<FactorySample> list(@RequestBody @ApiIgnore FactorySample factorySample, Integer curPage, Integer pageSize) {
        Page<FactorySample> page = new Page<>(pageSize, curPage);
        List<FactorySample> factorySamples = factorySampleSV.list(factorySample, page.genRowStart(), page.getPageSize());
        int total = factorySampleSV.count(factorySample);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return factorySamples;
    }


    /**
     * 查询FactorySample信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询FactorySample信息集合", notes = "查询FactorySample信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<FactorySample> listByPk(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode, Integer curPage, Integer pageSize) {
        Page<FactorySample> page = new Page<>(pageSize, curPage);
        List<FactorySample> factorySamples = factorySampleSV.list(id, sampleCode, factoryCode, page.genRowStart(), page.getPageSize());
        int total = factorySampleSV.count(id, sampleCode, factoryCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return factorySamples;
    }

    /**
     * 统计FactorySample信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计FactorySample信息数量根据主键", notes = " 统计FactorySample信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        return factorySampleSV.count(id, sampleCode, factoryCode);
    }

    /**
     * 统计FactorySample信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计FactorySample信息数量", notes = "统计FactorySample信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable,禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "ver", value = "版本", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody FactorySample factorySample) {
        return factorySampleSV.count(factorySample);
    }


    /**
     * 创建FactorySample
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建FactorySample", notes = "创建FactorySample")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sampleCode", value = "sampleCode", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "factoryCode", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public FactorySample build(@RequestBody @ApiIgnore FactorySample factorySample) {
        factorySampleSV.save(factorySample);
        return factorySample;
    }


    /**
     * 修改FactorySample
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改FactorySample", notes = "修改FactorySample")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable,禁用 Disable", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public FactorySample modify(@RequestBody @ApiIgnore FactorySample factorySample) {
        if (factorySample == null) {
            return new FactorySample();
        }
        factorySampleSV.modify(factorySample);
        return factorySample;
    }

    /**
     * 删除FactorySample
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除FactorySample", notes = "删除FactorySample")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "sampleCode", value = "样品编码", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        factorySampleSV.delete(id, sampleCode, factoryCode);
        return BeanRet.create(true, "删除FactorySample成功");
    }

}
